import 'package:star_author/config/ui_constant.dart';
import 'package:star_author/utils/common_util/date_util.dart';
import 'package:star_author/utils/common_util/toast/custom_toast.dart';
import 'package:star_author/utils/http/http_util.dart';
import 'package:star_author/widgets/cover_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../../config/base_configuration.dart';

//todo:显示详情用于禁言
class UserInfoDialog extends StatefulWidget {
  Map map;
  String banId;

  UserInfoDialog({Key? key, this.map: const {}, this.banId: ""})
      : super(key: key);

  @override
  State<UserInfoDialog> createState() => _UserInfoDialogState();
}

class _UserInfoDialogState extends State<UserInfoDialog> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getList();
  }

  getList() async {
    ///api/v1/studios/{id}/banned_user_list
    HttpUtil.commonRequest(Get.context!,
            "/api/v1/studios/${StreamConf.liveId}/banned_user_list",
            queryParameters: {"user_id": widget.banId},
            isErrorToast: false,
            isCatchErrorLogin: false,
            isLoading: false)
        .then((value) {
      if (value.data['data'] == null || value.data['data'].length <= 0) {
        isBand = false;
      } else {
        for (int i = 0; i < value.data['data'].length; i++) {
          if (value.data['data'][i]['id'].toString() ==
              widget.banId.toString()) {
            if (DateUtil.getDateTime(value.data['data'][i]['time'])!
                    .difference(DateTime.now())
                    .inSeconds >
                0) {
              isBand = true;
            } else {
              isBand = false;
            }
          }
        }
        setState(() {});
      }
    });
  }

  bool isBand = false;

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 206.w,
      width: Get.width,
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(16.w),
      ),
      child: Stack(
        clipBehavior: Clip.none,
        children: [
          Positioned(
            child: buildCircleCover(size: 68, cover: widget.map['cover'] ?? ""),
            top: -34.w,
            left: Get.width / 2 - 34.w,
          ),
          Container(
            margin: EdgeInsets.only(
              top: 34.w + 8.w,
            ),
            child: Column(
              children: [
                Container(
                  child: Text(
                    "${widget.map['user_nickname']}",
                    style: TextStyle(
                      fontSize: 16.sp,
                      color: UIConstant.color33,
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                  alignment: Alignment.center,
                  margin: EdgeInsets.only(bottom: 30.w),
                ),
                Container(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: [
                      // Container(
                      //   alignment: Alignment.center,
                      //   height: 42.w,
                      //   width: 130.w,
                      //   decoration: BoxDecoration(
                      //       color: Colors.white,
                      //       borderRadius: BorderRadius.circular(4.w),
                      //       border: Border.all(
                      //         color: UIConstant.color66,
                      //         width: 1,
                      //       )),
                      //   child: Row(
                      //     mainAxisAlignment: MainAxisAlignment.center,
                      //     children: [
                      //       Text(
                      //         "设为管理员",
                      //         style: TextStyle(
                      //           fontSize: 14.sp,
                      //           color: UIConstant.color33,
                      //         ),
                      //       ),
                      //     ],
                      //   ),
                      // ),
                      GestureDetector(
                        child: Container(
                          alignment: Alignment.center,
                          height: 42.w,
                          width: 130.w,
                          decoration: BoxDecoration(
                              color: Colors.white,
                              borderRadius: BorderRadius.circular(4.w),
                              border: Border.all(
                                color: UIConstant.color66,
                                width: 1,
                              )),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              Text(
                                isBand ? "解除禁言" : "禁言",
                                style: TextStyle(
                                  fontSize: 14.sp,
                                  color: UIConstant.color33,
                                ),
                              ),
                            ],
                          ),
                        ),
                        onTap: () {
                          if (isBand) {
                            uBand();
                          } else {
                            band();
                          }
                        },
                      )
                    ],
                  ),
                )
              ],
            ),
          )
        ],
      ),
    );
  }

  band() {
    HttpUtil.commonRequest(
      Get.context!,
      "/api/v1/studios/${StreamConf.liveId}/ban_user",
      method: HttpUtil.MethodPost,
      data: {"user_id": widget.banId},
    ).then((value) {
      if (value.statusCode == 200) {
        CustomToast.show("禁言成功");
        setState(() {
          isBand = true;
        });
        Get.back();
      }
    });
  }

  uBand() {
    HttpUtil.commonRequest(
        Get.context!, "/api/v1/studios/${StreamConf.liveId}/unban_user",
        method: HttpUtil.MethodPost,
        data: {"user_id": widget.banId}).then((value) {
      if (value.statusCode == 200) {
        Get.back();
        setState(() {
          isBand = false;
        });
        CustomToast.show("取消禁言成功");
      }
    });
  }
}

class AnchorDialog extends StatefulWidget {
  const AnchorDialog({Key? key}) : super(key: key);

  @override
  State<AnchorDialog> createState() => _AnchorDialogState();
}

class _AnchorDialogState extends State<AnchorDialog> {
  @override
  Widget build(BuildContext context) {
    return Container(
        height: 229.w,
        width: Get.width,
        padding: EdgeInsets.only(
          top: 20.w,
          left: 12.w,
          right: 12.w,
        ),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(16.w),
        ),
        child: Container(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              Row(
                children: [
                  buildCircleCover(size: 40),
                  Container(
                    height: 40.w,
                    margin: EdgeInsets.only(
                      left: 8.w,
                    ),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          "主播 ",
                          style: TextStyle(
                              fontSize: 14.0.sp,
                              color: UIConstant.color33,
                              fontWeight: FontWeight.w500),
                        ),
                        Text(
                          "0观看 ｜  1 在看",
                          style: TextStyle(
                            fontSize: 12.0.sp,
                            color: UIConstant.color99,
                          ),
                        )
                      ],
                    ),
                  )
                ],
              ),
              Container(
                margin: EdgeInsets.only(
                  top: 21.w,
                ),
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Text(
                      "本场直播",
                      style: TextStyle(
                        fontSize: 12.sp,
                        color: UIConstant.color33,
                      ),
                    ),
                    SizedBox(
                      width: 8.w,
                    ),
                    Container(
                      decoration: BoxDecoration(
                        color: UIConstant.colorE7F6D1,
                        borderRadius: BorderRadius.circular(10.w),
                      ),
                      padding:
                          EdgeInsets.symmetric(vertical: 2.w, horizontal: 15.w),
                      child: Text(
                        "翡翠01号直播间",
                        style: TextStyle(
                          color: UIConstant.color33,
                          fontSize: 12.sp,
                        ),
                      ),
                    )
                  ],
                ),
              ),
              Container(
                margin: EdgeInsets.only(top: 10.w),
                child: Row(
                  children: [
                    Container(
                      margin: EdgeInsets.only(right: 10.w),
                      width: (Get.width * (170 / 375)),
                      height: 68.w,
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Text(
                            "已讲解货品数",
                            style: TextStyle(
                              fontSize: 12.sp,
                              color: UIConstant.color33,
                            ),
                          ),
                          Text(
                            "200",
                            style: TextStyle(
                                fontSize: 20.sp,
                                color: UIConstant.color33,
                                fontWeight: FontWeight.w500),
                          ),
                        ],
                      ),
                      decoration: BoxDecoration(
                          color: UIConstant.colorF6F6,
                          borderRadius: BorderRadius.circular(8.w)),
                    ),
                    Container(
                      width: (Get.width * (170 / 375)),
                      height: 68.w,
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Text(
                            "已讲解货品数",
                            style: TextStyle(
                              fontSize: 12.sp,
                              color: UIConstant.color33,
                            ),
                          ),
                          Text(
                            "200",
                            style: TextStyle(
                                fontSize: 20.sp,
                                color: UIConstant.color33,
                                fontWeight: FontWeight.w500),
                          ),
                        ],
                      ),
                      decoration: BoxDecoration(
                          color: UIConstant.colorF6F6,
                          borderRadius: BorderRadius.circular(8.w)),
                    ),
                  ],
                ),
              )
            ],
          ),
        ));
  }
}
